package com.web.farme.redis;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.JSONSerializer;

import java.util.List;

public class FastJsonRedisSerializer implements RedisSerializer {

    private final JSONSerializer jsonSerializer = new JSONSerializer();

    @Override
    public <T> String serialize(T message) {
        if (message instanceof String) {
            return message.toString();
        }
        return JSON.toJSONString(message);
    }

    @Override
    public <T> String serializeList(List<T> message) {
        return JSON.toJSONString(message);
    }

    @Override
    public <T> T deSerialize(String message, Class<T> tClass) {
        return JSON.parseObject(message, tClass);
    }

    @Override
    public <T> List<T> deSerializeList(String message, Class<T> tClass) {
        return JSON.parseArray(message, tClass);
    }
}
